﻿using System;
using System.Configuration;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate;

namespace FoundationLib.Data.NHibernate.Configuration
{
	/// <summary>
	/// Represents a NHibernate configuration element.
	/// </summary>
	public class NHibernateConfigElement : ConfigurationElement
	{
		/// <summary>
		/// Creates a new <see cref="NHibernateConfigElement"/>.
		/// </summary>
		public NHibernateConfigElement()
			: base()
		{
		}

		/// <summary>
		/// Gets the name of the resource, which is either embedded in <see cref="Assembly"/> or a path pointing to 
		/// the NHibernate configuration file.
		/// </summary>
		[ConfigurationProperty("resource", IsRequired = true, DefaultValue = "hibernate.cfg.xml")]
		public string Resource
		{
			get
			{
				return (this["resource"] as string);
			}
		}

		/// <summary>
		/// Gets the name of the assembly, used in combination with <see cref="Resource"/>.
		/// </summary>
		[ConfigurationProperty("assembly", IsRequired = false, DefaultValue = null)]
		public string Assembly
		{
			get
			{
				return (this["assembly"] as string);
			}
		}

		/// <summary>
		/// Gets the flush mode of the NHibernate session.
		/// </summary>
		[ConfigurationProperty("flushMode", IsRequired = false, DefaultValue = FlushMode.Auto)]
		public FlushMode FlushMode
		{
			get
			{
				return ((FlushMode)Enum.Parse(typeof(FlushMode), this["flushMode"] as string, true));
			}
		}
	}
}
